package com.ruoyi.web.controller.combat.socialmedia;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.combat.domain.userlocation.CombatBlog;
import com.ruoyi.combat.service.userlocation.ICombatBlogService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户发布内容Controller
 *
 * @author ruoyi
 * @date 2024-08-30
 */
@Api(tags = "课题三、课题五：网络抗定位、抗关联-用户发布内容管理")
@RestController
@RequestMapping("/userlocation/blog")
public class CombatBlogController extends BaseController {
    @Autowired
    private ICombatBlogService combatBlogService;

    /**
     * 查询用户发布内容列表
     */
    @ApiOperation(value = "查询用户发布内容列表")
    @PreAuthorize("@ss.hasPermi('system:blog:list')")
    @GetMapping("/list")
    public TableDataInfo list(CombatBlog combatBlog) {
        startPage();
        List<CombatBlog> list = combatBlogService.selectCombatBlogList(combatBlog);
        return getDataTable(list);
    }

    /**
     * 导出用户发布内容列表
     */
    @ApiOperation(value = "导出用户发布内容列表")
    @PreAuthorize("@ss.hasPermi('system:blog:export')")
    @Log(title = "用户发布内容", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CombatBlog combatBlog) {
        List<CombatBlog> list = combatBlogService.selectCombatBlogList(combatBlog);
        ExcelUtil<CombatBlog> util = new ExcelUtil<CombatBlog>(CombatBlog.class);
        util.exportExcel(response, list, "用户发布内容数据");
    }

    /**
     * 获取用户发布内容详细信息
     */
    @ApiOperation(value = "获取用户发布内容详细信息")
    @PreAuthorize("@ss.hasPermi('system:blog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(combatBlogService.selectCombatBlogById(id));
    }

    /**
     * 新增用户发布内容
     */
    @ApiOperation(value = "新增用户发布内容")
    @PreAuthorize("@ss.hasPermi('system:blog:add')")
    @Log(title = "用户发布内容", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CombatBlog combatBlog) {
        return toAjax(combatBlogService.insertCombatBlog(combatBlog));
    }

    /**
     * 修改用户发布内容
     */
    @ApiOperation(value = "修改用户发布内容")
    @PreAuthorize("@ss.hasPermi('system:blog:edit')")
    @Log(title = "用户发布内容", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CombatBlog combatBlog) {
        return toAjax(combatBlogService.updateCombatBlog(combatBlog));
    }

    /**
     * 删除用户发布内容
     */
    @ApiOperation(value = "删除用户发布内容")
    @PreAuthorize("@ss.hasPermi('system:blog:remove')")
    @Log(title = "用户发布内容", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(combatBlogService.deleteCombatBlogByIds(ids));
    }

    /**
     * 根据用户id查看用户的所有发文
     */
    @ApiOperation(value = "根据用户id查看用户的所有发文")
    @PreAuthorize("@ss.hasPermi('system:user:query')")
    @GetMapping(value = "/user")
    public TableDataInfo getBlogByUserId(@RequestParam String userId) {
        startPage();
        List<CombatBlog> list = combatBlogService.getBlogsByUserId(userId);
        return getDataTable(list);
    }

    /**
     * 发文趋势统计
     * @return
     */
    @ApiOperation(value = "根据用户id查看用户的发文趋势统计")
    @GetMapping(value = "/sendStatistics")
    public AjaxResult sendStatistics(String userId) {
        return AjaxResult.success(combatBlogService.sendStatistics(userId));
    }
    /**
            * 数量统计
     * @return
             */
    @ApiOperation(value = "根据用户id查看用户的发文趋势统计")
    @GetMapping(value = "/numberStatistics")
    public AjaxResult numberStatistics(String userId) {
        return AjaxResult.success(combatBlogService.numberStatistics(userId));
    }
}
